require_relative '../../spec-helper.rb'
begin
  require 'xmlsimple' unless defined? XmlSimple
rescue Exception => e
  require 'xml-simple' unless defined? XmlSimple
end

describe "Conversation" do

  it "should be able to extract data from a xml" do
    options = {
      :xml => "<ec2-ebs-volumes type=\"array\">
        <ec2-ebs-volume>
          <aws-id>vol-1</aws-id>
          <aws-status>available</aws-status>
        </ec2-ebs-volume>
        <ec2-ebs-volume>
          <aws-id>vol-2</aws-id>
          <aws-status>available</aws-status>
        </ec2-ebs-volume>
      </ec2-ebs-volumes>",
      :parse_options => { 'forcearray' => ['item', 'member'], 'suppressempty' => nil, 'keeproot' => false }
    }

    response = XmlSimple.xml_in(options[:xml], options[:parse_options])
    volume_node = response["ec2-ebs-volume"].select {|k| k["aws-id"] == "vol-1"}
    volume_node[0]["aws-id"].should == "vol-1"
  end

end